<template>
  <div class="page-container">
    <el-card>
      <el-row
        :gutter="20"
        class="mb-2"
      >
        <el-col :span="8">
          <el-input
            v-model="search"
            placeholder="搜索订单号/用户"
            clearable
            @clear="onSearch"
            @keyup.enter="onSearch"
          />
        </el-col>
      </el-row>
      <el-table
        :data="filteredOrders"
        style="width: 100%"
      >
        <el-table-column
          prop="orderId"
          label="订单号"
        />
        <el-table-column
          prop="username"
          label="用户"
        />
        <el-table-column
          prop="bikeId"
          label="单车编号"
        />
        <el-table-column
          prop="status"
          label="状态"
        />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button
              size="small"
              @click="showDetail(scope.row)"
            >
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
      v-model="detailDialog"
      title="订单详情"
    >
      <el-descriptions :column="1">
        <el-descriptions-item label="订单号">
          {{ detail.orderId }}
        </el-descriptions-item>
        <el-descriptions-item label="用户">
          {{ detail.username }}
        </el-descriptions-item>
        <el-descriptions-item label="单车编号">
          {{ detail.bikeId }}
        </el-descriptions-item>
        <el-descriptions-item label="状态">
          {{ detail.status }}
        </el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <el-button @click="detailDialog = false">
          关闭
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
export default { name: 'OrderManagementPage' }
</script>

<script setup lang="ts">
import { ref, computed } from 'vue'
const orders = ref([
  { orderId: 'O1001', username: '张三', bikeId: 'B001', status: '已完成' },
  { orderId: 'O1002', username: '李四', bikeId: 'B002', status: '进行中' },
  { orderId: 'O1003', username: '王五', bikeId: 'B003', status: '已取消' }
])
const search = ref('')
const page = ref(1)
const filteredOrders = computed(() => {
  let data = orders.value
  if (search.value) {
    data = data.filter(o => o.orderId.includes(search.value) || o.username.includes(search.value))
  }
  return data
})
const detailDialog = ref(false)
const detail = ref({ orderId: '', username: '', bikeId: '', status: '' })
function onSearch() { page.value = 1 }
function showDetail(row: any) {
  detail.value = { ...row }
  detailDialog.value = true
}
</script>

<style scoped>
.page-container { padding: 24px; }
.mb-2 { margin-bottom: 16px; }
</style> 